package com.example.hello_world.fragments2;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.LayoutInflater;

import com.example.hello_world.R;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class FraActivity extends AppCompatActivity {

    private ViewPager viewPager;
    List<Fragment> fragments;
    FragmentAdapter adapter;
    private TabLayout tabLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fra);
        viewPager=findViewById(R.id.viewpager);
        tabLayout=findViewById(R.id.tabLayout);
//        FragmentManager fragmentTransaction=getSupportFragmentManager();
//        FragmentTransaction fragmentTransaction1 = fragmentTransaction.beginTransaction();
//        fragmentTransaction1.add(new oneFragment(),null);
//        fragmentTransaction1.commit();
        fragments=new ArrayList<>();
        fragments.add(new oneFragment());
        fragments.add(new twoFragment());
        adapter=new FragmentAdapter(getSupportFragmentManager(),fragments);
        viewPager.setAdapter(adapter);
        tabLayout.addTab(tabLayout.newTab());
        tabLayout.addTab(tabLayout.newTab());
        tabLayout.setupWithViewPager(viewPager);
    }
}